

package com.example.daxiguaforharmony.manager;

import com.harmonyos.app.ICrossDevicePlayerInterface;
import ohos.rpc.IRemoteObject;
import ohos.rpc.RemoteException;
import ohos.rpc.MessageParcel;
import ohos.rpc.MessageOption;

public class CrossDevicePlayerInterfaceProxy implements ICrossDevicePlayerInterface {
    private static final String DESCRIPTOR = "com.harmonyos.app.CrossDevicePlayerInterface";

    private static final int COMMAND_SEND_COMMAND = IRemoteObject.MIN_TRANSACTION_ID;

    private final IRemoteObject remote;
    private static final int ERR_OK = 0;

    public CrossDevicePlayerInterfaceProxy(
        /* [in] */ IRemoteObject remote) {
        this.remote = remote;
    }

    @Override
    public IRemoteObject asObject() {
        return remote;
    }

    @Override
    public void sendCommand(
        /* [in] */ int command,
        /* [in] */ long soundId) throws RemoteException {
        MessageParcel data = MessageParcel.obtain();
        MessageParcel reply = MessageParcel.obtain();
        MessageOption option = new MessageOption(MessageOption.TF_SYNC);

        data.writeInterfaceToken(DESCRIPTOR);
        data.writeInt(command);
        data.writeLong(soundId);

        try {
            remote.sendRequest(COMMAND_SEND_COMMAND, data, reply, option);
            reply.readException();
        } finally {
            data.reclaim();
            reply.reclaim();
        }
    }
};

